﻿using DLog.Access.Context;
using DLog.Access.Repository;
using DLog.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLog.Access
{
    public class SqlServerDal : Repository<LogModel>, IDal
    {
        public SqlServerDal(string connectionString)
            : base(new DLogContext(connectionString))
        {
        }

        public LogModel SelectModel(string logId)
        {
            return base.Find(p => p.LogId == logId);
        }

        public List<LogModel> SelectList()
        {
            return base.Filter(p => 1 == 1).ToList();
        }

        public List<LogModel> SelectList(int logLevel)
        {
            return base.Filter(p => p.LogLevel == logLevel).ToList();
        }

        public List<LogModel> SelectList(int pageIndex, int pageSize, out int totalCount)
        {
            return base.Filter(p => 1 == 1, out totalCount, pageIndex, pageSize).ToList();
        }

        public List<LogModel> SelectList(int logLevel, int pageIndex, int pageSize, out int totalCount)
        {
            return base.Filter(p => p.LogLevel == logLevel, out totalCount, pageIndex, pageSize).ToList();
        }

        public List<LogModel> SelectList(DateTime createStartDate, DateTime createEndDate, int pageIndex, int pageSize, out int totalCount)
        {
            return base.Filter(p => p.CreateDate > createStartDate && p.CreateDate < createEndDate, out totalCount, pageIndex, pageSize).ToList();
        }

        public List<LogModel> SelectList(int logLevel, DateTime createStartDate, DateTime createEndDate, int pageIndex, int pageSize, out int totalCount)
        {
            return base.Filter(p => p.LogLevel == logLevel && p.CreateDate > createStartDate && p.CreateDate < createEndDate, out totalCount, pageIndex, pageSize).ToList();
        }

        public int Delete(string logId)
        {
            return base.Delete(p => p.LogId == logId);
        }
    }
}
